package com.dqyt.khjc.controller;

import com.dqyt.khjc.bean.ReceiptTbBeanDTO;
import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.service.ReceiptTbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 接收单
 */
@RestController
public class ReceiptTbController {
    @Autowired
    private ReceiptTbService receiptTbService;

    /**
     * 新增接收单
     * @param request
     * @param rwdbh
     * @param hxqNumber
     * @param fhqpNumber
     * @param startNumber
     * @param endNumber
     * @param wtfId
     * @param wtf
     * @param sjr
     * @param jsrq
     */
    @RequestMapping(value = "/api/addReceipt", method = {RequestMethod.POST})
    public  ResultMsg addReceipt(HttpServletRequest request,String rwdbh,int hxqNumber,int fhqpNumber,
                            String startNumber,String endNumber,long wtfId,String wtf,
                                 String sjr,String sjrPhone,String jsrq,String bz,long wtfchId,String wtfch,

                                 @RequestParam(name = "mzjy", required = false, defaultValue = "0") Integer mzjy,
                                 @RequestParam(name = "mzwx", required = false, defaultValue = "0") Integer mzwx,
                                 @RequestParam(name = "qpjy", required = false, defaultValue = "0") Integer qpjy,
                                 @RequestParam(name = "qpcz", required = false, defaultValue = "0") Integer qpcz,
                                 @RequestParam(name = "ghqp", required = false, defaultValue = "0") Integer ghqp,
                                 @RequestParam(name = "ghpf", required = false, defaultValue = "0") Integer ghpf,


                                 @RequestParam(name = "isManual", required = false, defaultValue = "0") Integer isManual,
                                 @RequestParam(name = "add_mz_st", required = false, defaultValue = "") String add_mz_st,
                                 @RequestParam(name = "add_mz_ed", required = false, defaultValue = "") String add_mz_ed,
                                 @RequestParam(name = "add_qp_st", required = false, defaultValue = "") String add_qp_st,
                                 @RequestParam(name = "add_qp_ed", required = false, defaultValue = "") String add_qp_ed




                                  ){

        if(isManual==0){
            ResultMsg resultMsg = receiptTbService.addReceipt(request,rwdbh,hxqNumber,fhqpNumber,
                    startNumber,endNumber,wtfId,wtf,sjr,sjrPhone,jsrq,bz,wtfchId,wtfch,mzjy,mzwx,qpjy,qpcz,ghqp,ghpf);
            return resultMsg;
        }else{
            ResultMsg resultMsg = receiptTbService.addReceipt2(request,rwdbh,hxqNumber,fhqpNumber,
                    wtfId,wtf,sjr,sjrPhone,jsrq,bz,wtfchId,wtfch,mzjy,mzwx,qpjy,qpcz,ghqp,ghpf,isManual,add_mz_st,add_mz_ed,add_qp_st,add_qp_ed);
            return resultMsg;
        }


    }

    /**
     * 新增接收单2(手动输入编号)
     * @param request
     */
    @RequestMapping(value = "/api/addReceipt2", method = {RequestMethod.POST})
    public  ResultMsg addReceipt2( HttpServletRequest request, @RequestBody ReceiptTbBeanDTO receipt){

        ResultMsg resultMsg = receiptTbService.addReceipt3(request,receipt);
        return resultMsg;
    }


    /**
     * 分页查询接收单
     * @param request
     * @param page
     * @param size
     * @param rwdbh
     * @param wtfId
     * @return
     */
    @RequestMapping(value = "/api/getReceiptListPage", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg getReceiptListPage(HttpServletRequest request,
                                     @RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer size,
                                     @RequestParam(name = "rwdbh", required = false, defaultValue = "") String rwdbh,
                                     @RequestParam(defaultValue = "-1") Integer wtfId,
                                     @RequestParam(defaultValue = "-1") Integer wtfchId

    ){
        ResultMsg resultMsg = receiptTbService.getReceiptListPage(request,page,size,rwdbh,wtfId,wtfchId);
        return resultMsg;
    }



    /**
     * 查询最新的接受单
     * @param request
     * @return
     */
    @RequestMapping(value = "/api/getReceiptFirst", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg getReceiptFirst(HttpServletRequest request){
        ResultMsg resultMsg = receiptTbService.getReceiptFirst(request);
        return resultMsg;
    }



    /**
     * 分页查询接收单 未签字的
     * @param request
     * @param page
     * @param size
     * @param rwdbh
     * @param wtfId
     * @return
     */
    @RequestMapping(value = "/api/getReceiptWqzListPage", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg getReceiptWqzListPage(HttpServletRequest request,
                                        @RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer size,
                                        @RequestParam(name = "rwdbh", required = false, defaultValue = "") String rwdbh,
                                        @RequestParam(defaultValue = "-1") Integer wtfId
    ){
        ResultMsg resultMsg = receiptTbService.getReceiptWqzListPage(request,page,size,rwdbh,wtfId);
        return resultMsg;
    }


    /**
     * 根据任务单编号删除接收单
     * @param request
     * @param rwdbh
     */
    @RequestMapping(value = "/api/delReceiptByrwdbh", method = {RequestMethod.POST})
    public  ResultMsg delReceiptByrwdbh(HttpServletRequest request,String rwdbh){
        ResultMsg resultMsg = receiptTbService.delReceiptByrwdbh(request,rwdbh);
        return resultMsg;
    }


    /**
     * 设置 驳回工作量确认单
     * @param request
     * @param jsdId
     * @param bhgyy
     * @return
     */
    @RequestMapping(value = "/api/rejectQrdDal", method = {RequestMethod.POST})
    public  ResultMsg rejectQrdDal(HttpServletRequest request,long jsdId,String bhgyy,String rwdbh){
        ResultMsg resultMsg = receiptTbService.rejectQrdDal(request,jsdId,bhgyy,rwdbh);
        return resultMsg;
    }


    /**
     * 设置 工作量确认单转到下一级
     * @param request
     * @param jsdId
     * @return
     */
    @RequestMapping(value = "/api/srtQrdProgress", method = {RequestMethod.POST})
    public  ResultMsg srtQrdProgress(HttpServletRequest request,long jsdId,String rwdbh){
        ResultMsg resultMsg = receiptTbService.srtQrdProgress(request,jsdId,rwdbh);
        return resultMsg;
    }


    /**
     * 设置 通过 通工作量确认单
     * @param request
     * @param jsdId
     * @return
     */
    @RequestMapping(value = "/api/srtQrdOkProgress", method = {RequestMethod.POST})
    public  ResultMsg srtQrdOkProgress(HttpServletRequest request,long jsdId,String rwdbh){
        ResultMsg resultMsg = receiptTbService.srtQrdOkProgress(request,jsdId,rwdbh);
        return resultMsg;
    }




}
